<!DOCTYPE html>
<html lang="zh-cn" xmlns:th="http://www.thymeleaf.org">
<header th:replace="base/top9"></header>
<div class="box-width">
    <div class="zixun-banner">
        <a href="">
            <img src="../images/zixun-banner.jpg">
        </a>
    </div>
</div>
<div class="box-width">
    <div class="box-mar-top20 clearfix">
        <div class="pull-left con01_left">
            <div class="ExhibitionInfo">
                <h2 class="title">
                    <span>产业资讯</span>
                    <div class="pull-right homeInfoTab">
                        <div id="application-info-show">
                        </div>
                    </div>
                </h2>
                <div class="ExhibitionInfo-box">
                    <ul class="id1" id="page-info-show">

                    </ul>
                    <div class="clearfix" id="page-info-page">

                    </div>
                </div>
            </div>
        </div>
        <!--引入右边图片-->
        <div th:replace="base/commom::home_right"></div>
    </div>
</div>

<!--引入home的底部-->
<div th:replace="base/commom::home_foot"></div>
</body>

<!--引入公共js-->
<div th:replace="base/commom::common_js"></div>

<!-- 自定义 jQuery -->
<script src="../js/supplement.js"></script>
<script type="text/javascript">

    //页面加载完成后
    $(function () {
        //初始加载产业资讯
        queryInfoById("", "", 1);

        // 给产业资讯的栏目标题添加触发事件
        $("#application-info-show").on('click', 'a', function () {
            var id = $(this).attr("data-id");
            var columnNames = $(this).attr("data-value");
            queryInfoById(id, columnNames, 1)
        });

        //获取城市ajax
        $.ajax({
            url: 'https://api.map.baidu.com/location/ip?ak=UUSbLbC8EGKlYZELPuSK4hZWOSKeLgGG',
            type: 'POST',
            dataType: 'jsonp',
            success: function (data) {
                $('#citys').html(data.content.address_detail.city)
            }
        });
    })

    //通过产业资讯所属栏目类别ID、栏目名称、页数，去查询列表信息
    function queryInfoById(id, columnNames, pageNum) {
        $.ajax({
            type: "get",
            url: "../industryInfo/getInfoList",
            data: {
                id: id,
                columnNames: columnNames,
                pageNum: pageNum
            },
            dataType: "json",
            success: function (resData) {
                var data = resData.data;
                // 产业资讯渲染
                var sortInfoList = data.sortInfoList;
                //校验栏目名称是否为空控制"推荐"是否高亮
                if (data.columnNames == '') {
                    var sortInfoListHtml = "<a class='active' data-id='' data-value='' data-target='#tab2Content' >推荐</a>";
                } else {
                    var sortInfoListHtml = "<a class=''  data-id='' data-value='' data-target='#tab2Content' >推荐</a>";
                }
                //当前栏目名称高亮显示
                for (var i = 0; i < sortInfoList.length; i++) {
                    if (sortInfoList[i].informationName == data.columnNames) {
                        sortInfoListHtml += "<a class='active'  data-id='" + sortInfoList[i].id + "' data-value='" + sortInfoList[i].informationName + "'>" + sortInfoList[i].informationName + "</a>"
                    } else {
                        sortInfoListHtml += "<a data-id='" + sortInfoList[i].id + "' data-value='" + sortInfoList[i].informationName + "'>" + sortInfoList[i].informationName + "</a>"
                    }
                }
                //渲染产业资讯栏目名称
                $("#application-info-show").html(sortInfoListHtml);

                // 分页器渲染
                var allNum = data.allNum; //总记录数
                var pageS = data.pageS;  //每页显示多少条
                var pageNum = data.pageNum; //当前页数
                var pageHtml = '';
                pageHtml += '  <ul id="myPager" class="pager pull-right" data-ride="pager" data-page="' + pageNum + '"' +
                    '          data-rec-total="' + allNum + '" data-rec-per-page="' + pageS + '" data-max-nav-count="4"' +
                    '           data-elements="first,prev_icon,nav,next_icon,last,total_page_text,goto">' +
                    '            </ul>';
                $("#page-info-page").html(pageHtml);
                $("#myPager").pager({
                    onPageChange: function (page) {
                        var urls = window.location.href;
                        if (urls.indexOf("page") == -1) {
                            if (urls.indexOf("?") == -1) {
                                urls = urls + "?page=" + page.page;
                            } else {
                                urls = urls + "&page=" + page.page;
                            }

                        } else {
                            if (urls.indexOf("?") == -1) {
                                urls = urls.substring(0, urls.indexOf("page") - 1) + "?page=" + page.page;
                            } else {
                                if (urls.indexOf("?page") == -1) {
                                    urls = urls.substring(0, urls.indexOf("page") - 1) + "&page=" + page.page;
                                } else {
                                    urls = urls.substring(0, urls.indexOf("page") - 1) + "?page=" + page.page;
                                }
                            }

                        }
                        var id = $("#application-info-show a.active").attr("data-id");
                        var columnNames = $("#application-info-show a.active").attr("data-value");
                        var pageNum = page.page;
                        queryInfoById(id, columnNames, pageNum)
                    }
                });

                // 栏目对应的列表渲染
                var pageList = data.pageList;
                var pageListHtml = "";
                for (var i = 0; i < pageList.length; i++) {
                    // 图片显示
                    var picHtml = ''
                    if (pageList[i].coverImgFileId == null || pageList[i].coverImgFileId == '') {
                        picHtml += '<dt><img src="../images/zwimg.png" ></dt>';
                    } else {
                        picHtml += '<dt><img  src=\"' + pageList[i].coverImgFileUrl + '\" ></dt>'
                    }
                    //渲染页面
                    pageListHtml += '<li>' +
                        '<a onclick=getDefaultIndustryInfo(&quot;' + pageList[i].id + '&quot;)  target="_blank" >' +
                        '<dl class="ExhibitionInfo-list container-flex">' +
                        picHtml +
                        '<dd class="col-flex-1">' +
                        '<p class="title">' + pageList[i].informationTitleLong + '</p >' +
                        '<p class="info-c">' + pageList[i].articleSource + '</p >' +
                        '<p class="info-tip">' +
                        '<span class="info-tip-time">' + dateFormat('MM-dd',pageList[i].createTime) + '</span>' +
                        '<div class="info-tip-ly">' +
                        '<span><i class="iconfont">&#xe617;</i>' + pageList[i].informationHits + '</span>' +
                        '<span><i class="iconfont">&#xe603;</i>' + pageList[i].informationLike + '</span>' +
                        /*'<span><i class="iconfont">&#xe609;</i>' + pageList[i].informationLike + '</span>' +*/
                        '</div>' +
                        '</p >' +
                        '</dd>' +
                        '</dl>' +
                        '</a>' +
                        '</li>'
                }
                $("#page-info-show").html(pageListHtml);

            }

        })

    }

    //查看产业资讯点击量加一
    function getDefaultIndustryInfo(id) {
        $.ajax({
            type: "post",
            url: "../industryInfo/updateClickRate",
            data: {"id": id},    //{"传递到后台的参数名":参数},
            dataType: 'json',//后台返回的数据格式类型
            success: function (data) {
                if (data.code == "200") {
                    url = "../industryInfo/induArtDetail?id=" + id;
                    window.open(url, "_blank");
                } else {
                    new $.zui.Messager("浏览失败，请联系管理员", {
                        type: 'warning', // 定义颜色主题
                        placement: 'center'//定义位置
                    }).show();
                }
            }
        })

    }

    //获取当前页数
    var getPageNum = function () {
        var pageNum = '';
        if (!$("#myPager").attr("data-page")) {
            pageNum = '1'
        } else {
            pageNum = $("#myPager").attr("data-page");
        }
        return pageNum;
    }

    /*
    * 时间格式化方法
    * var 时间戳
    * fmt 时间模板 例如：yyyy-MM-dd HH:mm:ss
    * */
    function dateFormat(fmt, val) {
        var date = null;
        if (val != null && val != '') {
            date = new Date(val);
        }else{
            return "";
        }
        var o = {
            "M+": date.getMonth() + 1,     //月份
            "d+": date.getDate(),     //日
            "h+": date.getHours(),     //小时
            "m+": date.getMinutes(),     //分
            "s+": date.getSeconds(),     //秒
            "q+": Math.floor((date.getMonth() + 3) / 3), //季度
            "S": date.getMilliseconds()    //毫秒
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }

    //企业工作台
    function registerUser() {
        window.location.href = "../enterprise/person";
    }


</script>


</html>